﻿using System;
using NUnit.Framework;
using StartReading.Security.Validation;

namespace StartReading.Tests.Security.Tests.Validation
{
    [TestFixture]    
    class PasswordValidationTests 
    {
        private string Password { get; set; }
        private TestDelegate IsValid { get; set; }

        private void IsPasswordValid()
        {
            PasswordValidation.Instance.IsValid( this.Password );
        }

        [SetUp]
        public void BeforeEachTest()
        {
            this.IsValid = this.IsPasswordValid;
        }

        [TearDown]
        public void AfterEachTest()
        {
            this.Password = null;
            this.IsValid = null;
        }

        [Test]
        public void IsValid_PasswordLengthSameAsMinimumPasswordLength_NoException()
        {
            this.Password = "123abc";
            Assert.DoesNotThrow( this.IsPasswordValid );
        }

        [Test]
        public void IsValid_PasswordLengthMoreThanMinimumPasswordLength_NoException()
        {
            this.Password = "123abc!@#";
            Assert.DoesNotThrow( this.IsPasswordValid );
        }

        [Test]
        public void IsValid_PasswordLengthLessThanMinimumPasswordLength_ThrowsArgumentException()
        {
            this.Password = "123";
            Assert.Throws( typeof( ArgumentException ), this.IsPasswordValid );
        }

        [Test]
        public void IsValid_EmptyPassword_ThrowsArgumentException()
        {
            this.Password = String.Empty;
            Assert.Throws( typeof( ArgumentException ), this.IsPasswordValid );
        }

        [Test]
        public void IsValid_NullPassword_ThrowsArgumentException()
        {
            this.Password = null;
            Assert.Throws( typeof( ArgumentException ), this.IsPasswordValid );
        }
    }
}
